import java.util.Random;
import java.util.Scanner;

public class Lab_01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Random random = new Random();
        int correctCount = 0;
        
        System.out.println("===== 100以内加减法口算练习 =====");
        System.out.println("请在下方输入答案，按Enter键确认。");
        System.out.println("\n开始答题：");
        
        for (int i = 1; i <= 50; i++) {
            // 生成两个100以内的随机数
            int num1 = random.nextInt(100);
            int num2 = random.nextInt(100);
            
            // 随机决定是加法还是减法（0表示加法，1表示减法）
            int operation = random.nextInt(2);
            
            int correctAnswer;
            String question;
            
            if (operation == 0) {
                // 加法
                correctAnswer = num1 + num2;
                question = "第" + i + "题: " + num1 + " + " + num2 + " = ";
            } else {
                // 减法，确保结果非负
                if (num1 < num2) {
                    // 交换两个数，确保减法结果非负
                    int temp = num1;
                    num1 = num2;
                    num2 = temp;
                }
                correctAnswer = num1 - num2;
                question = "第" + i + "题: " + num1 + " - " + num2 + " = ";
            }
            
            // 显示题目并获取用户答案
            System.out.print(question);
            int userAnswer = scanner.nextInt();
            
            // 检查答案是否正确
            if (userAnswer == correctAnswer) {
                System.out.println("答案正确！");
                correctCount++;
            } else {
                System.out.println("答案错误！正确答案是: " + correctAnswer);
            }
        }
        
        // 显示最终成绩
        System.out.println("\n===== 练习完成 =====");
        System.out.println("总题目数: 50");
        System.out.println("答对题目数: " + correctCount);
        System.out.println("正确率: " + String.format("%.1f", (correctCount / 50.0) * 100) + "%");
        
        scanner.close();
    }
}